<template>
  <div>
    <TopFilter :list="topFilterList" :cols="4" :collapse="false" labelWidth="100" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      selectionType="single"
      :isSelectColumn="false"
      columnsRef="yfkmxcxTable"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary" @click="exportExcelReceiveData" >导出</el-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" title="预收款明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detailModal :formData="formData" :queryType="queryType" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { prepayCustomer,exportExcelData } from '@/api/finance/advancesReceived/registerQuery';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils/index';
import detailModal from './detailModal';
export default {
  name: 'RegisterQuery',
  components: { detailModal },
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilters(),
      fetchParams: { xhrAbort: true },
      visible: false,
      fetchApi: prepayCustomer,
      columns: this.createTableColumns(),
      formData: {},
      queryType:"",
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '客户编号',
          fieldName: 'customerCode',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入...'
        },
        {
          type: 'SELECT',
          label: '收款类别',
          fieldName: 'RECEIVE_TYPE',
          placeholder: '请输入...',
          disabled: false,
          initialValue: 80301004,
          itemList: [
            { text: '预收款', value: 80301004 },
            { text: '保险费', value: 80301005 },
            { text: '其他', value: 80301008 }
          ]
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 120,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" icon="el-icon-document" onClick={() => this.queryDetail(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },

        {
          title: '客户代码',
          dataIndex: 'CUSTOMER_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: '200'
        },
        {
          title: '地址',
          dataIndex: 'ADDRESS',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 300
        },
        {
          title: '邮编',
          dataIndex: 'ZIP_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人电话',
          dataIndex: 'CONTACTOR_PHONE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人手机',
          dataIndex: 'CONTACTOR_MOBILE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '收款金额',
          dataIndex: 'PRE_PAY',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        }
      ];
    },
    queryDetail(val) {
      this.formData = val;
      this.queryType = this.topFilterList.find(x => x.fieldName ==="RECEIVE_TYPE").initialValue;
      this.visible = true;
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    exportExcelReceiveData(){
      exportExcelData(this.fetchParams).then(res => {
        console.log(res);
        exportExcelFile(res, '预收款明细导出');
      });
    }
  }
};
</script>

<style lang="less" scoped></style>
